<?php
/**
 * Created by PhpStorm.
 * User: 程序猴
 * Date: 2018/5/11
 *  Q Q: 505413
 * Time: 17:11
 */

namespace app\admin\controller;
use app\admin\controller\Base;
use think\Db;
class Order extends Base
{
    //全部订单
    public function allOrder()
    {
        $list = Db::name('order')
                ->alias('a')
                ->join('cxh_member b','a.user_id=b.id','left')
                ->field(['a.*','b.nickname'])
                ->order('order_id desc')
                ->paginate(10);
        $this->assign('list',$list);
        return $this->fetch();
    }
    //已支付订单
    public function yOrder()
    {
        $list = Db::name('order')
            ->alias('a')
            ->join('cxh_member b','a.user_id=b.id','left')
            ->field(['a.*','b.nickname'])
            ->order('order_id desc')
            ->where(array('pay_status'=>1))
            ->paginate(10);
        //dump($list);exit;
        $this->assign('list',$list);
        return $this->fetch();
    }
    //未支付订单
    public function nOrder()
    {
        $list = Db::name('order')
            ->alias('a')
            ->join('cxh_member b','a.user_id=b.id','left')
            ->field(['a.*','b.nickname'])
            ->order('order_id desc')
            ->where(array('pay_status'=>0))
            ->paginate(10);
        //dump($list);exit;
        $this->assign('list',$list);
        return $this->fetch();
    }
    //修改支付状态
    public function status_edit()
    {
        $order_id = input('param.order_id');
        $status = Db::name('order')->where('order_id',$order_id)->value('pay_status');//判断当前状态情况
        if($status==1)
        {
            $flag = Db::name('order')->where('order_id',$order_id)->setField(['pay_status'=>0]);
            return json(['code' => 1, 'data' => $flag['data'], 'msg' => '未支付']);
        }
        else
        {
            $flag = Db::name('order')->where('order_id',$order_id)->setField(['pay_status'=>1]);
            return json(['code' => 0, 'data' => $flag['data'], 'msg' => '已支付']);
        }

    }
    //删除订单
    public function orderDel()
    {
        $order_id = input('order_id');
        $res = Db::name('order')->where(array('order_id'=>$order_id))->delete();
        if($res){
            return json(['code' => 1, 'url' => 'order/allOrder', 'msg' => '删除订单成功']);
        }else{
            return json(['code' => -1, 'url' => 'order/allOrder', 'msg' => '删除订单失败，请重试']);
        }
    }
}